package StudyCode.summary.myfile;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class IsAudioFile {
	public static void main(String[] args) {
		String fileName = "E:\\迅雷下载\\test1.txt";
		System.out.println("文件 " + fileName + " 是音频文件吗？" + isAudioFile(fileName));
	}

	private static boolean isAudioFile(String filename) {
		if (!(filename.length() > 3)) {
			return false;
		}

		int i = filename.length();
		String ending = filename.substring(i - 3, i);
		if (ending.equalsIgnoreCase(".au")) {
			return true;
		}

		ending = filename.substring(i - 4, i);

		if (ending.equalsIgnoreCase(".mp3"))
			return true;

		if (ending.equalsIgnoreCase(".wav")) {
			return true;
		}

		if (ending.equalsIgnoreCase(".ogg")) {
			return true;
		}

		if (ending.equalsIgnoreCase(".3gp")) {
			return true;
		}

		if (ending.equalsIgnoreCase(".mid"))
			return true;

		int index = i - 5;
		if (index >= 0) {
			ending = filename.substring(index, i);
			if (ending.equalsIgnoreCase(".fake")) {
				return true;
			}
		}

		return false;
	}
}
